﻿#region Copyright & licence

// This file is part of Refix.
// 
// Refix is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// 
// Refix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with Refix.  If not, see <http://www.gnu.org/licenses/>.
// 
// Copyright (C) 2010-11 David Musgrove and others.

#endregion

using System;

using NUnit.Framework;

using Refix.Core.Structure;

namespace Refix.Core.Tests
{
    [TestFixture]
    public class ExtensionsTest
    {
        [Test]
        public void IsMatchFor_Exact_Match_Passes()
        {
            Assert.True("1.2.3.4".IsMatchFor("1.2.3.4"));
        }

        [Test]
        public void IsMatchFor_Partial_Version_Match_Passes()
        {
            Assert.True("1.2.3.4".IsMatchFor("1.2.3"));
            Assert.False("1.2.3.4".IsMatchFor("1.2.4"));
        }

        [Test]
        public void IsMatchFor_Plus_Pattern_Match_Passes()
        {
            Assert.True("1.2.3.4".IsMatchFor("1.2.3+"));
            Assert.True("1.2.4.4".IsMatchFor("1.2.3+"));
            Assert.False("1.2.2.4".IsMatchFor("1.2.3+"));
        }

        [Test]
        public void IsMatchFor_Wildcard_Match_Passes()
        {
            Assert.True("1.2.3.4".IsMatchFor("1.2.*"));
            Assert.False("1.2.3.4".IsMatchFor("1.3.*"));
        }

        [Test]
        public void IsSystemAssemblyName_Works()
        {
            Assert.True("System".IsSystemAssemblyName());
            Assert.False("System.Web.Mvc".IsSystemAssemblyName());
            Assert.False("System.Web.Abstractions".IsSystemAssemblyName());
            Assert.False("System.Web.Routing".IsSystemAssemblyName());
            Assert.False("No.Such.Assembly".IsSystemAssemblyName());
            Assert.True("UIAutomationProvider".IsSystemAssemblyName());
        }

        [Test]
        public void PositionOf_ReturnsFirst()
        {
            Assert.AreEqual(Position.First, new[] { "a", "b", "c", "d", "e" }.PositionOf("a"));
        }

        [Test]
        public void PositionOf_ReturnsLast()
        {
            Assert.AreEqual(Position.Last, new[] { "a", "b", "c", "d", "e" }.PositionOf("e"));
        }

        [Test]
        public void PositionOf_ReturnsNormal()
        {
            Assert.AreEqual(Position.Normal, new[] { "a", "b", "c", "d", "e" }.PositionOf("b"));
        }
    }
}